<?php
declare (strict_types = 1);

namespace app\controller\backend\system;

use app\controller\backend\BackendController;
use app\service\logic\backend\system\MenuService;
use think\App;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\response\Json;

class MenuController extends BackendController
{
    protected $service;

    public function __construct(App $app, MenuService $service)
    {
        parent::__construct($app);

        $this->service = $service;
    }

    /**
     * 显示资源列表
     *
     * @return Json
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function index()
    {
        $admin = $this->request->middleware('admin');
        $menu = $this->service->getListByPermissions($admin);

        return amis($menu);
    }
}
